#include "ksprite.h"

KSprite::KSprite(const char* image)
{
    imagePath = image;

    GLint alignment;
    QImage buf;
    buf.load(imagePath);

    texture = QGLWidget::convertToGLFormat( buf );

    width = texture.width();
    height = texture.height();

    glGenTextures(1, &texId);
    glBindTexture( GL_TEXTURE_2D, texId );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);//??
    glPixelStorei (GL_UNPACK_ALIGNMENT, 1);//??

    glTexImage2D(GL_TEXTURE_2D,
                0, GL_RGBA,
                texture.width(), texture.height(),
                0,                          //border
                GL_RGBA, GL_UNSIGNED_BYTE,
                texture.bits());
    glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
}

void KSprite::setPosition(GLfloat x, GLfloat y) {
    posX = x;
    posY = y;
}

KSprite::~KSprite()
{

}

